<head>
    <title>团队列表</title>
    <link href="/lego/static/css/bootstrap.css" rel="stylesheet"/>
    <link href="/lego/static/css/header.css" rel="stylesheet"/>
    <link href="/lego/static/css/teamList.css" rel="stylesheet"/>
    <link href="/lego/static/css/xcConfirm.css" rel="stylesheet"/>
    <script src="/lego/static/js/jquery.1.11.3.min.js"></script>
    <script src="/lego/static/js/bootstrap.js"></script>
    <script src="/lego/static/js/underscore-min.js"></script>
    <script src="/lego/static/js/xcConfirm.js"></script>
    <script type="text/javascript">
        $(function () {
            initData();
        });

        //初始化表格数据
        function initData() {
            $.ajax({
                url: '/lego/getAllTeam',
                type: 'GET',
                success: function (data) {
                    if (data && data.code == 200) {
                        $('#teamListTable').html(_.template($('#teamList_template').html())({
                            data: data.data
                        }));
                    }
                }
            });
        }

        function joinTeam(teamId) {
            $.ajax({
                url: '/lego/joinTeam',
                type: 'GET',
                data: {'teamId': teamId},
                success: function (data) {
                    if (data && data.code == 200) {
                        var op = {
                            title: "提示信息",
                            btn: window.wxc.xcConfirm.btnEnum.ok,
                            onOk: function () {
                                if (data.msg == "加入成功") {
                                    initData();
                                }
                            }
                        }
                        if (data.msg == "加入成功") {
                            window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.success, op);
                        } else {
                            window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.error, op);
                        }
                    }
                }
            });
        }

        function leaveTeam(teamId) {
            $.ajax({
                url: '/lego/leaveTeam',
                type: 'GET',
                data: {'teamId': teamId},
                success: function (data) {
                    if (data && data.code == 200) {
                        var op = {
                            title: "提示信息",
                            btn: window.wxc.xcConfirm.btnEnum.ok,
                            onOk: function () {
                                if (data.msg == "移出成功") {
                                    initData();
                                }
                            }
                        }
                        if (data.msg == "移出成功") {
                            window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.success, op);
                        } else {
                            window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.error, op);
                        }
                    }
                }
            });
        }

        function deleteTeam(teamId) {
            var txt = "确认删除该团队吗?";
            var option = {
                title: "提示信息",
                btn: window.wxc.xcConfirm.btnEnum.okcancel,
                onOk: function () {
                    $.ajax({
                        url: '/lego/validateBeforeDeleteTeam',
                        type: 'GET',
                        data: {'teamId': teamId},
                        success: function (data) {
                            if (data && data.code == 200) {
                                var op = {
                                    title: "提示信息",
                                    btn: window.wxc.xcConfirm.btnEnum.okcancel,
                                    onOk: function () {
                                        actualDeleteTeam(teamId);
                                    }
                                }
                                if (data.msg == "验证通过") {
                                    actualDeleteTeam(teamId);
                                } else {
                                    window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.custom, op);
                                }
                            }
                        }
                    });
                }
            }
            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.warning, option);
        }

        //真正删除组
        function actualDeleteTeam(teamId) {
            $.ajax({
                url: '/lego/deleteTeam',
                type: 'POST',
                data: {'teamId': teamId},
                success: function (data) {
                    if (data && data.code == 200) {
                        var op = {
                            title: "提示信息",
                            btn: window.wxc.xcConfirm.btnEnum.ok,
                            onOk: function () {
                                if (data.msg == "删除成功") {
                                    initData();
                                }
                            }
                        }
                        if (data.msg == "删除成功") {
                            window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.success, op);
                        } else {
                            window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.error, op);
                        }
                    }
                }
            });
        }
    </script>
</head>
<body>
<#include "../navigationBar.ftl">
<header class="jumbotron subhead" id="overview">
    <div class="container">
        <h1>QA团队管理</h1>
        <h5>所有操作的第一步,先加入你的团队吧!!!</h5>
    </div>
</header>

<div class="text-right" style="margin-right: 200px;margin-bottom: 20px">
    <a class="btn btn-primary" href="/lego/addTeamIndex" target="_blank">
        <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> 加入您的QA团队信息
    </a>
</div>
<div id="teamListTable"></div>
<#include "../common/template.ftl">
</body>
